require('../css/commonCss/normalize.css')
require('../css/commonCss/basic.css')
require('../css/commonCss/property.css')
require('../css/commonCss/reset.css')
require('../liabs/iconfont/iconfont.css')
require('../css/commonCss/footer.less')
require('../css/mine.less')

//引入axios
require('axios')
const axios = require('axios')

//引入weui
require('weui')
const weui = require('weui.js')

//引入组件
const util = require('../util/util')


/* 
获取元素
*/
const imgurl = document.querySelector('#imgurl')
const nickname = document.querySelector('#nickname')
const userId = localStorage.getItem('userId')
const autograph = document.querySelector('#autograph')
const dynamic = document.querySelector('#dynamic')
const time = document.querySelector('#time')
console.log(time)
const calorie = document.querySelector('#calorie')
const signOut = document.querySelector('#signOut')
const motionData = document.querySelector('#motionData')
const badge = document.querySelector('#badge')

axios.get("http://139.9.177.51:8099/users/mysportsBadge?userId=" + userId).then(function (res) {
    let user = res.data.data.user;
    /* console.log(user) */

    //渲染数据
    if (user.imgurl) {
        imgurl.src = user.imgurl;
    }
    if (user.sign) {
        autograph.textContent = user.sign;
    }
    nickname.textContent = user.nickname;
    console.log(res)

    dynamic.textContent = res.data.data.dynamicCount + '条';

    time.textContent = Math.ceil(res.data.data.sports.times/60);
    calorie.textContent = res.data.data.sports.calorie

})

signOut.addEventListener('click', function () {
    weui.confirm('您确定要退出吗', function () {
        //清除本地存储
        localStorage.clear()
        //跳转到登录页面
        location.href = './logoin.html'
    })
})

motionData.addEventListener('click', function () {
    location.href = './motionData.html'
})

badge.addEventListener('click', function () {
    location.href = './badge.html'
})


//底部导航
util.fixBottomNav('mine')

